06. Comparison Operators
Comparison Operators
Question:
Start Quiz:
#
# Find all the llamas born between January 1, 1995 and December 31, 1998.
# Fill in the 'where' clause in this query.
QUERY = '''
select name from animals where ...
'''
User's Answer:
(Note: The answer done by the user is not guaranteed to be correct)
#
# Find all the llamas born between January 1, 1995 and December 31, 1998.
# Fill in the 'where' clause in this query.
QUERY = '''
select name from animals where species = 'llama' and birthdate > '1995-1-1' and birthdate < '1998-12-31'
'''
Solution:
INSTRUCTOR NOTE:
The big difference between comparison operators in SQL and in Python is that we use = for equality in SQL, whereas Python uses ==.
The columns in the animals table are name (a text string), species (also a text string), and birthdate (a date).
Reminder: Dates in our databases will always be in the international standard format, e.g. '1999-12-31'. Make sure to put single quotes around dates.
The comparison operators in SQL are almost the same as the ones in Python: < for less than, > for greater than, != for not equal, <= for less than or equal, and so forth.
One difference is that SQL uses = instead of == to represent equality. You can apply all the basic comparison operators to strings, numbers, dates, and other values.
As a preview, here's the SQL command used to initially create this table:
create table animals ( name text, species text, birthdate date );
a
The comparison operators in SQL are almost the same as the ones in Python: < for less than, > for greater than, != for not equal, <= for less than or equal, and so forth.
One difference is that SQL uses = instead of == to represent equality. You can apply all the basic comparison operators to strings, numbers, dates, and other values.
The columns in the animals table are name (a text string), species (also a text string), and birthdate (a date).
Reminder: Dates in our databases will always be in the international standard format, e.g. '1999-12-31'. Make sure to put single quotes around dates.
As a preview, here's the SQL command used to initially create this table:
create table animals (
name text,
species text,
birthdate date
);